package com.ksj.task;

import com.ksj.controller.WebSocketServer;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Component
public class WebSocketTask {

    /**
     * 通过静态方法获取WebSocket实例
     */
    @Scheduled(cron = "0/5 * * * * ?")
    public void sendMessageToClient() {
        WebSocketServer instance = WebSocketServer.getInstance();
        if (instance != null) {
            instance.sendToAllClient(
                    "服务端消息: " +
                            DateTimeFormatter.ofPattern("HH:mm:ss").format(LocalDateTime.now())
            );
        }
    }
}